﻿using Max.PH5_2008A.ShoppingCode.Domain;
using Max.PH5_2008A.ShoppingCode.IRespository;
using Max.PH5_2008A.ShoppingCode.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH5_2008A.ShoppingCode.Service
{
    public class MemberInfoService : BaseService<MemeberInfoEntity>, IMemberInfoService
    {
        IMemberInfoRespository _respositry;
        /*
         * 避坑
         * 
         * 用自己的仓储接口去实现
         * 
         * **/
        public MemberInfoService(IMemberInfoRespository respositry) : base(respositry)
        {
            _respositry = respositry;
        }


        public (bool,string,MemeberInfoEntity) Login(string username, string password)
        {
            string msg = "登录成功";
            bool flag = true;
            var data = _respositry.Query().Where(x => x.Phone.Equals(username)).ToList();
            if(data == null || data.Count() <= 0)
            {
                msg= "用户不存在";
                flag = false;
                return (flag, msg, new MemeberInfoEntity());
            }

            data = data.Where(x => x.Password.Equals(password)).ToList();
            if (data == null || data.Count() <= 0)
            {
                msg= "密码不对";
                flag= false;
                return (flag, msg, new MemeberInfoEntity());
            }

            var result = data.FirstOrDefault();
            return (flag,msg,result);
        }
    }
}
